package groupware;
import java.util.Map; 
import java.util.HashMap;
import java.util.Date;

import javax.jdo.PersistenceManager;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.Inheritance;
import javax.jdo.annotations.InheritanceStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
@Inheritance(strategy = InheritanceStrategy.SUBCLASS_TABLE)

public class Contact{
	  @PrimaryKey
	  @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	  private Key key;
	  
	  @Persistent
	  private String address;
	  
	  @Persistent
	  private String telephone;
	  
	  @Persistent
	  private String fax;

	  @Persistent
	  private String email;

	  @Persistent
	  private String website;

	  //Log Class Add
	   @Persistent(serialized="true")
	   private Map<Date,String> log = new HashMap<Date,String>();
	 
	   public Contact(
				  String address,
			      String telephone, 
			      String fax,
			      String email,
			      String website) {
				  
			    this.address = address;
			    this.telephone = telephone;
			    this.fax = fax;
			    this.email = email;
			    this.website = website;
			    
			  }

	   public void save() {
	        DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
			Entity currentContact = new Entity("Contact");
			currentContact.setProperty("address", this.address);
			currentContact.setProperty("telephone", this.telephone);
			currentContact.setProperty("fax", this.fax);
			currentContact.setProperty("email", this.email);
			currentContact.setProperty("website", this.website);
	        this.key = datastore.put(currentContact); 
	   }
	   
	  public Key getKey() {
	    return key;
	  }


	}
